package com.lebang.lechuangsystem.service.sys;

import com.lebang.lechuangsystem.domain.Permission;
import com.lebang.lechuangsystem.domain.Role;
import com.lebang.lechuangsystem.domain.RolePermission;
import com.lebang.lechuangsystem.mapper.PermissionMapper;
import com.lebang.lechuangsystem.mapper.RolePermissionMapper;
import com.lebang.lechuangsystem.po.RolePermissionPo;
import com.lebang.lechuangsystem.po.RolePo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: hwq
 * @Date: 2019/8/22 14:11
 * @Version 1.0
 */
@Service
@Slf4j
public class RoleService extends BaseService<Role, RolePo> {
    @Autowired
    private PermissionMapper permissionMapper;
    @Autowired
    private RolePermissionMapper rolePermissionMapper;

    public List<Permission> selectPermissionListByRoleId(Integer roleId) {
        return permissionMapper.selectPermissionListByRoleId(roleId);
    }

    public int rolePermissionAdd(Integer roleId, List<String> stringList) {
        rolePermissionMapper.deleteByRoleId(roleId);
        return rolePermissionMapper.rolePermissionAdd(roleId, stringList);
    }

    public List<RolePermission> selectAllList(Integer roleId){
        RolePermissionPo example=new RolePermissionPo();
        example.createCriteria().andRoleIdEqualTo(roleId);
        return rolePermissionMapper.selectByExample(example);
    }
}
